//
//  TabBarController.swift
//  SinaBlog
//
//  Created by 李超 on 16/3/20.
//  Copyright © 2016年 lichao. All rights reserved.
//

import UIKit

class TabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let custumTabBar = CustomTabBar()
        //设置点击回调闭包
        custumTabBar.addComposeBtnActionHandler = {
            let composeVC = ComposeController()
            self.presentViewController(UINavigationController(rootViewController: composeVC), animated: true, completion: nil)
            
        }
        //设置自定义的tabBar
      self.setValue(custumTabBar, forKey: "tabBar")
     
       //添加控制器
       addChildViewControllers()
    }

    func addChildViewControllers(){
        
        let homeVC = HomeViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        let messageVC = MessageViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        let discoverVC = DiscoverViewController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        let profileVC = ProfileViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }
    
    func addChildViewController(Controller: UIViewController ,title:String ,imageName:String) {
        
        Controller.title = title
        Controller.tabBarItem.image = UIImage(named: imageName)
        //设置图片的渲染模式
        let hilightImage = imageName+"_highlighted"
        Controller.tabBarItem.selectedImage = UIImage(named: hilightImage)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字的颜色
        Controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //通过navigationController进行添加
        addChildViewController(UINavigationController(rootViewController: Controller))
   
        
    }
    
}
